package com.est.dase;

import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnKeyListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;

import com.est.dase.widget.Status;
import com.est.dase.widget.WAYWidget;
/**
*
* @author Fernando Geraldes, Jaime Santos, Jorge Silva
*
*/
public class Options extends Activity{
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.more_options);
		
		TextView textView = (TextView) findViewById(R.id.text_more_option);
		textView.setText("Status");
		
		Status s = Status.getInstance(this);
		
		String[] status = new String[5];
		
		status[0]=s.getStatusName(0);
		status[1]=s.getStatusName(1);
		status[2]=s.getStatusName(2);
		status[3]=s.getStatusName(3);
		status[4]=s.getStatusName(4);
		
		//Resources r = getResources();
		//Drawable d = r.getDrawable(R.drawable.tab_bg_unselected);
		
		TextView more_textView = (TextView) findViewById(R.id.moreTitle);
		more_textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
		more_textView.setText(R.string.settings_opt3);
		
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, status);
		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

		final Spinner spinner = (Spinner) findViewById(R.id.spinner1);
		spinner.setAdapter(adapter);
		
		spinner.setSelection(Status.getInstance(this).getStatus());
		
		// Quando carrega no spinner
		//Status.getInstance(this).setStatus(valor);
		//E Enviar notificacao para ser apanhada pelo receiver do widget
		spinner.setOnItemSelectedListener(new OnItemSelectedListener() {

			public void onItemSelected(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {
				Status.getInstance(Options.this).setStatus(arg2);
				WAYWidget.actualizar(Options.this, spinner.getItemAtPosition(arg2).toString());
			}

			public void onNothingSelected(AdapterView<?> arg0) {
				
			}
		});
		
		
		TextView textOther = (TextView) findViewById(R.id.text_other);
		textOther.setText(R.string.status_other);
		
		final EditText editOther = (EditText) findViewById(R.id.edit_other);
		editOther.setText(Status.getInstance(this).getOutro());
		editOther.setOnKeyListener(new OnKeyListener() {
			
			public boolean onKey(View v, int keyCode, KeyEvent event) {
				Status.getInstance(Options.this).setOutro(editOther.getEditableText().toString());
				
				return false;
			}
		});
		
	}
}
